package com.keyue.controller;


import com.keyue.common.annotation.AnonymousAccess;
import com.keyue.common.constant.ServerResult;
import com.keyue.common.jsr303.OperateGroup;
import com.keyue.domain.vo.CarInfoQueryVO;
import com.keyue.domain.vo.CarInfoVO;
import com.keyue.service.CarInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 车辆信息(CarInfo)表控制层
 *
 * @author makejava
 * @since 2025-07-02 11:44:58
 */
@RestController
@RequestMapping("/keyue/admin/car")
public class CarInfoController {
    /**
     * 服务对象
     */
    @Resource
    private CarInfoService carInfoService;

    /**
     * 分页查询
     *
     * @param carInfoQueryVO 查询条件
     * @return 查询结果
     */
    @AnonymousAccess
    @PostMapping("/list_by_page")
    public ServerResult listByPage(@RequestBody @Validated({OperateGroup.List.class}) CarInfoQueryVO carInfoQueryVO) {
        return carInfoService.listByPage(carInfoQueryVO);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param carInfoQueryVO 查询条件
     * @return 单条数据
     */
    @AnonymousAccess
    @PostMapping("/query_by_id")
    public ServerResult queryById(@RequestBody CarInfoQueryVO carInfoQueryVO) {
        return carInfoService.queryById(carInfoQueryVO);
    }

    /**
     * 新增数据
     *
     * @param carInfoVO 数据VO
     * @return 新增结果
     */
    @AnonymousAccess
    @PostMapping("/add")
    public ServerResult add(@RequestBody CarInfoVO carInfoVO) {
        return carInfoService.add(carInfoVO);
    }

    /**
     * 编辑数据
     *
     * @param carInfoVO 数据VO
     * @return 编辑结果
     */
    @AnonymousAccess
    @PostMapping("/edit")
    public ServerResult edit(@RequestBody CarInfoVO carInfoVO) {
        return carInfoService.edit(carInfoVO);
    }

    /**
     * 删除数据
     *
     * @param carInfoQueryVO 查询条件
     * @return 删除是否成功
     */
    @AnonymousAccess
    @PostMapping("/delete_by_id")
    public ServerResult deleteById(@RequestBody CarInfoQueryVO carInfoQueryVO) {
        return carInfoService.deleteById(carInfoQueryVO);
    }

}

